<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>rabbitMq</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../../css/public.css" media="all" />
</head>
<body class="childrenBody">
    <form class="layui-form">
        <div class="layui-form-item">
            <input type="text" placeholder="请输入推送内容"
                   autocomplete="off" id="serdMessage" class="layui-input">
        </div>
        <div class="layui-form-item">
            <input type="button" class="layui-input" id="sender" value="消息发送">
        </div>
        <div class="layui-form-item">
            <input type="button" class="layui-input" id="receiver" value="消息接收">
        </div>
        <div class="layui-form-item">
            <input type="button" class="layui-input" id="clearMessage" value="清空消息">
        </div>
        <div class="layui-form-item">
            <textarea id="receiveMessage" class="layui-textarea"></textarea>

        </div>
    </form>
    <script type="text/javascript" src="../../js/layui/layui.js"></script>
    <script type="text/javascript" src="../../js/public.js"></script>
    <script type="text/javascript">
        layui.use(['form','layer'],function(){
            var $ = layui.jquery
                , layer = parent.layer === undefined ? layui.layer : top.layer
                , form = layui.form;

            // 向后台发送消息
            function sendMessage() {
                $.ajax({
                    url: WEBAPP_ROOTPATH + "/rabbitmq/message/sender",
                    type: "POST",
                    data: {message: $("#serdMessage").val()},
                    async : false,
                    success: function (data) {
                    }
                })
            }

            // 从后台接收消息
            function receiveMessage(){
                $.ajax({
                    url: WEBAPP_ROOTPATH + "/rabbitmq/message/receiver",
                    type: "GET",
                    async : false,
                    success: function (data) {
                        $("#receiveMessage").val(data);
                    }
                })
            }

            // 清空后台接收的消息
            function clearMessage(){
                $.ajax({
                    url: WEBAPP_ROOTPATH + "/rabbitmq/message/clear",
                    type: "GET",
                    async : false,
                    success: function (data) {

                    }
                })
            }

            $("#sender").click(function () {
                sendMessage();
            });

            $("#receiver").click(function () {
                receiveMessage();
            });

            $("#clearMessage").click(function () {
                clearMessage();
            });
        });
    </script>
</body>
</html>